﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MaLu.Common;
using System.Data;
using System.Text;
using MaLu.BusiLogic;

namespace MaluJg.web.Poverty
{
    public partial class Poverty : ProvertyPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();

            string _v = Village;
            if (_v == "全部")
                _v = string.Empty;
            DataTable dt = BLPoverty.GetAllowanceByYearAndVillage(Provider, Year, _v).Tables[0];

            StringBuilder sb = new StringBuilder();
            sb.Append(@"<chart caption='扶贫帮困资金'  bgColor='CCECFF' outCnvBaseFontSize='18' baseFontSize='14' baseFontColor='006699'  xAxisName='各种扶贫帮困资金' yAxisName='金额' showValues='0'	formatNumberScale='0' showBorder='1'>");
            float sum = 0.0f;
            if (dt.Rows.Count > 0)
            {
                string param = string.Empty;
                //if (Year != 0)
                //    param += "&year=" + Year;
                //if (Village != string.Empty)
                //    param += "&v=" + Village;
                //if (param != string.Empty)
                //    param = "?" + param.Substring(1);

                foreach (DataColumn item in dt.Columns)
                {
                    // sb.AppendFormat("<set label='{0}' value='{1}' link='n-{2}.aspx{3}' />", BLFarm.GetName(item.ColumnName), dt.Rows[0][item.ColumnName].ToString(), item.ColumnName, param);

                    sb.AppendFormat("<set label='{0}' value='{1}' link=\"JavaScript:myJS('{2}.aspx{3}')\" />", BLPoverty.GetName(item.ColumnName), dt.Rows[0][item.ColumnName].ToString(), item.ColumnName, param);
                    float temp = 0;
                    float.TryParse(dt.Rows[0][item.ColumnName].ToString(), out temp);
                    sum += temp;

                }


                sb.Append(@"</chart>");
                sb.Append(@"<chart caption='扶贫帮困资金'  bgColor='CCECFF' outCnvBaseFontSize='18' baseFontSize='14' baseFontColor='006699'  xAxisName='各种扶贫帮困资金' yAxisName='金额' showValues='0'	formatNumberScale='0' showBorder='1'>");

                param = string.Empty;
                if (Year != 0)
                    param += "&year=" + Year;
                if (VillageID != 0)
                    param += "&vid=" + VillageID;
                if (param != string.Empty)
                    param = "?" + param.Substring(1);

                foreach (DataColumn item in dt.Columns)
                {
                    // sb.AppendFormat("<set label='{0}' value='{1}' link='n-{2}.aspx{3}' />", BLFarm.GetName(item.ColumnName), dt.Rows[0][item.ColumnName].ToString(), item.ColumnName, param);
                    float percent = 0;
                    string _per = "0";
                    if (sum > 0)
                    {
                        float temp = 0;
                        float.TryParse(dt.Rows[0][item.ColumnName].ToString(), out temp);
                        percent = temp / sum * 100;
                        _per = Math.Round(percent, 2).ToString();
                    }
                    sb.AppendFormat("<set label='{0} {4}%' value='{1}' link=\"JavaScript:myJS('{2}.aspx{3}')\" />", BLPoverty.GetName(item.ColumnName), dt.Rows[0][item.ColumnName].ToString(), item.ColumnName, param, _per);

                }

            }
            sb.Append(@"</chart>");


            Response.Write(sb.ToString());
            Response.End();
        }
    }
}
